<?php
// A few notes:
//		- I wasn't sure about what we wanted to do Re: Uniqueness 
//		  (con name?), so there's no uniqueness checking yet
//		- There's not much security-minded code in there yet,
//		  as this is mostly just a proof of concept to show you guys
//		  so don't screw around too much with the id you pass to the page
//		- There is a default date format and time zone set in configuration.inc.php
//		- Convention::getStartTime() and Convention::getEndTime() can be passed
//		  a date format, to customize their return value

include_once('configuration.inc.php');
include_once('functions/db_functions.php');
include_once('objects/Convention.php');

db_connect();

$id = isset($_GET['id']) ? (int)$_GET['id'] : null;
$con = null;

// If we have an ID, get that con from the db
if ($id)
{
	$con = Convention::getConventionByID($id);
	
	
}
else
{
	$start = new DateTime(); // Just set them both to "now" for simplicity's sake
	$end = new DateTime();

	$con = new Convention('RunningGAGG', 'Geneseo', $start, $end);	// Create a new convention
	$con->save();	// Save it to the database, returning true on success, false on failure
	$con->setSite('Geneseo College Union'); // Change the site
	$con->save();	// Update the database with the new information
	$id = $con->getID();	// Get the convention's ID
}

// Write some basic HTML - probably do this with templates in the future, to separate
// the data management from the interface
?>
<!DOCTYPE html>
<html>
<head>
	<title><?php echo $con->getName(); ?></title>
</head>
<body>
<h1><?php echo $con->getName(); ?></h1>
<dl>
	<dt>Dates:</dt>
		<dd><?php echo $con->getStartTime().' to '.$con->getEndTime(); ?></dd>
	<dt>Event Submission:</dt>
		<dd><?php echo ($con->eventSubmit()) ? 'open' : 'closed'; ?></dd>
	<dt>Pre Registration:</dt>
		<dd><?php echo ($con->preReg()) ? 'open' : 'closed'; ?></dd>
	<dt>Onsite Registration:</dt>
		<dd><?php echo ($con->onsiteReg()) ? 'open' : 'closed'; ?></dd>
	<dt>Active:</dt>
		<dd><?php echo ($con->isActive()) ? 'active' : 'inactive'; ?></dd>
	<dt>Link:</dt>
		<dd><a href="example.php?id=<?php echo $con->getID(); ?>">link</a></dd>
</dl>
</body>
</html>